home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 12 / BBS in a box XII-2.iso / Files II / Prog / B-C / CDlog.sit / CDlog / CExampleDlog.p < prev    next >
Encoding:
Text File  |  1990-11-12  |  5.4 KB  |  221 lines  |  [TEXT/PJMM]

  1. unit UExampleDlog;
  2.  
  3. {    This unit contains CExampleDlog, a simple descendant of CDlog.  The dialog }
  4. {    includes three text fields, an OK button, a Cancel button, an ICON, a picture }
  5. {    item that changes appearance when you click it, a group of three radio buttons,}
  6. {    and three titled borders. }
  7. {}
  8. {    The OK button is disabled until there is a non-null entry in the 'Numeric Text' }
  9. {    field. }
  10. {}
  11. interface
  12.  
  13. uses
  14.     Script, TCL, {}
  15.     CDlog;
  16.  
  17. type
  18.     {    --------------------------------------------------------------------    }
  19.     {    CExampleDlog}
  20.     {}
  21.     {    A CDlog descendant that implements an example dialog.}
  22.     {}
  23.     {    SUPERCLASS = CDlog}
  24.     {    SUBCLASSES = None}
  25.     {    --------------------------------------------------------------------    }
  26.     CExampleDlog = object(CDlog)
  27.  
  28.             procedure IExampleDlog;                                        { Initialize }
  29.  
  30.             procedure DoCommand (                                            { Handle commands }
  31.                                         theCommand: longint);                    { Command number }
  32.             override;
  33.  
  34.             procedure SetOKButton;                                            { Set Ok button }
  35.         end;
  36.  
  37. procedure DoExampleDlog;
  38.  
  39. implementation
  40.  
  41. const
  42.  
  43. {Commands}
  44.     cmdRadio1 = 2401;
  45.     cmdRadio2 = 2402;
  46.     cmdRadio3 = 2403;
  47.     cmdEditNumber = 2404;
  48.  
  49. {Items in example dialog}
  50.     iLabel1 = 3;
  51.     iLabel2 = 4;
  52.     iSomeText = 5;
  53.     iNumericText = 6;
  54.     iMoreText = 7;
  55.     iLabel3 = 8;
  56.  
  57.     iIcon = 12;
  58.     iPicture = 13;
  59.     iUser = 14;
  60.  
  61. {Picture IDs}
  62.     kPictOne = 10241;
  63.     kPictTwo = 10242;
  64.  
  65. {Constants for use with controls}
  66.     kActive = 0;
  67.     kInActive = 255;
  68.  
  69. {Misc}
  70.     BORDER_OFFSET = 3;
  71.  
  72.     kExampleDlog = 1024;
  73.  
  74. procedure DoExampleDlog;
  75.     var
  76.         theDlog: CExampleDlog;
  77.  
  78.     begin
  79.         new(theDlog);
  80.         if theDlog <> nil then
  81.             theDlog.IExampleDlog;
  82.     end;
  83.  
  84. {    --------------------------------------------------------------------    }
  85. {    C E x a m p l e   D l o g   M e t h o d s                                                                }
  86. {    --------------------------------------------------------------------    }
  87. {    IExampleDlog}
  88. {}
  89. {            Initialize the example Dialog.}
  90. {    --------------------------------------------------------------------    }
  91. procedure CExampleDlog.IExampleDlog;
  92.     var
  93.         wRadioGroup: CDRadioGroup;
  94.         wBorder: CTitledBorder;
  95.         wFontInfo: FontInfo;
  96.         wLineHeight: integer;
  97.         wFrame: Rect;
  98.  
  99.     begin
  100.         IDlog(kExampleDlog, FALSE, nil, gApplication, systemFont, 12);
  101.         CDlogWind(itsWindow).SetModal(TRUE);
  102.  
  103.         { Get font info for use creating borders }
  104.         GetFontInfo(wFontInfo);
  105.         with wFontInfo do
  106.             wLineHeight := ascent + descent + leading;
  107.  
  108.         { Create borders }
  109.         SectPanes(itsPanes, iLabel1, iLabel3, wFrame);
  110.         InsetRect(wFrame, -BORDER_OFFSET, -BORDER_OFFSET);
  111.  
  112.         {Another adjustment to the border is necessary... the bottom,right item is}
  113.         {an editText item, and the pane in the 'itsPanes' list does not include the}
  114.         {outline.  So, add BORDER_OFFSET to bottom and right.}
  115.         with wFrame do begin
  116.             bottom := bottom + BORDER_OFFSET;
  117.             right := right + BORDER_OFFSET;
  118.         end;
  119.  
  120.         New(wBorder);
  121.         with wFrame do
  122.             wBorder.ITitledBorder(itsWindow, SELF, right - left, wLineHeight + (bottom - top), left, top - wLineHeight, sizFIXEDLEFT, sizFIXEDTOP, 'Text Fields:');
  123.         itsWindow.itsSubviews.BringFront(wBorder);
  124.  
  125.         {Give radio group same borderwidth as bordered items above it}
  126.         wRadioGroup := CDRadioGroup(itsRadioGroups.FirstItem);
  127.         wRadioGroup.SetBorderTitle('Radio Buttons:');
  128.         with wFrame do
  129.             wRadioGroup.CalcBorder(right - left, 0);
  130.  
  131.         SectPanes(itsPanes, iIcon, iUser, wFrame);
  132.         InsetRect(wFrame, -BORDER_OFFSET, -BORDER_OFFSET);
  133.         New(wBorder);
  134.         with wFrame do
  135.             wBorder.ITitledBorder(itsWindow, SELF, right - left, wLineHeight + (bottom - top), left, top - wLineHeight, sizFIXEDLEFT, sizFIXEDTOP, 'Graphic Items:');
  136.         itsWindow.itsSubviews.BringFront(wBorder);
  137.  
  138.         SetEdit(iSomeText, CdLenFiltOn, 8);
  139.         SetEdit(iNumericText, CdNumFiltOn + CdLenFiltOn, 3);
  140.         SetEdit(iMoreText, CdLenFiltOn, 4);
  141.  
  142.         CDEditText(itsPanes.NthItem(iNumericText)).SetClickCmd(cmdEditNumber);
  143.  
  144.         SetOKButton;
  145.  
  146.         {Set command for picture item; if clicked, the picture changes}
  147.         CDPicture(itsPanes.NthItem(iPicture)).SetClickCmd(kPictTwo);
  148.  
  149.         itsWindow.Select;
  150.     end;
  151.  
  152. {    --------------------------------------------------------------------    }
  153. {    DoCommand}
  154. {}
  155. {    Handles activity associated with dialog items.                                                }
  156. {    --------------------------------------------------------------------    }
  157. procedure CExampleDlog.DoCommand (theCommand: longint);
  158.     var
  159.         wGraphic: CDGraphic;
  160.  
  161.     begin
  162.         case theCommand of
  163.             cmdOK: 
  164.                 begin
  165.                 CloseWind(itsWindow);
  166.             end;
  167.  
  168.             cmdCancel: 
  169.                 begin
  170.                 CloseWind(itsWindow);
  171.             end;
  172.  
  173.             cmdRadio1, cmdRadio2, cmdRadio3: 
  174.                 begin
  175.                 CDRadioGroup(itsRadioGroups.NthItem(1)).SetStationID(theCommand - 2400);
  176.             end;
  177.  
  178.             cmdEditNumber: 
  179.                 SetOkButton;
  180.  
  181.             kPictOne: 
  182.                 begin
  183.                 CDPicture(itsPanes.NthItem(iPicture)).NewPicture(kPictOne);
  184.                 CDPicture(itsPanes.NthItem(iPicture)).SetClickCmd(kPictTwo);
  185.             end;
  186.  
  187.             kPictTwo: 
  188.                 begin
  189.                 CDPicture(itsPanes.NthItem(iPicture)).NewPicture(kPictTwo);
  190.                 CDPicture(itsPanes.NthItem(iPicture)).SetClickCmd(kPictOne);
  191.             end;
  192.  
  193.             cmdBadChar: 
  194.                 SysBeep(1);
  195.  
  196.             cmdBadLength: 
  197.                 SysBeep(1);
  198.  
  199.             otherwise
  200.                 inherited DoCommand(theCommand);
  201.         end; {case}
  202.     end; {DoCommand}
  203.  
  204. {    --------------------------------------------------------------------    }
  205. {    SetOKButton}
  206. {}
  207. {    Sets the OK button active or inactive based on the prerequisite items.            }
  208. {    --------------------------------------------------------------------    }
  209. procedure CExampleDlog.SetOKButton;
  210.     var
  211.         theString: Str255;
  212.  
  213.     begin
  214.         GetIText(iNumericText, theString);
  215.         if Length(theString) > 0 then
  216.             CDControl(itsPanes.NthItem(1)).Hilite(kActive)
  217.         else
  218.             CDControl(itsPanes.NthItem(1)).Hilite(kInActive);
  219.     end;
  220.  
  221. end.